package com.ss.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ss.model.TSysuser;
import com.ss.service.ISysUserService;


@Controller
@RequestMapping("/sysUserController")
public class SysUserController {
	private ISysUserService suservice;

	public ISysUserService getSuservice() {
		return suservice;
	}

	@Autowired
	public void setSuservice(ISysUserService suservice) {
		this.suservice = suservice;
	}

	private static final Logger logger = Logger
			.getLogger(SysUserController.class);
	
	/*
	 * 用户登录
	 * @request
	 * */
	@RequestMapping(value = "/login", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> onLogin(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String login = new String(request.getParameter("login"));
		String password = new String(request.getParameter("password"));
		TSysuser su = new TSysuser();
		su.setUserid(login);
		su.setPassword(password);
		boolean result = suservice.isExist(su);
		System.out.println(result);
		if (result) {
			request.getSession().setAttribute("sysuser", su);
			Map<String, Object> modelMap = new HashMap<String, Object>();
			modelMap.put("success", "true");
			return modelMap;
		} else {
			return null;
		}
	}
	

	@RequestMapping(params = "north")
	public String north() {
		return "layout/north";
	}

	@RequestMapping(params = "west")
	public String west() {
		return "layout/west";
	}

	@RequestMapping(params = "center")
	public String center() {
		return "layout/center";
	}

	@RequestMapping(params = "south")
	public String south() {
		return "layout/south";
	}



}
